import cv2 as cv

#读取摄像头
cap = cv.VideoCapture(0,cv.CAP_DSHOW)
falg = 1
num = 1
#cap = cv.VideoCapture('C:/Users/Ke/Pictures/Camera Roll/wang.mp4')
#等待
while (cap.isOpened()):
    ret_flag, frame = cap.read()
    cv.imshow("Capture_Test", frame)
    k = cv.waitKey(1) & 0xFF
    if k == ord('z'):
        cv.imwrite("C:/Users/Ke/Desktop/red/"+str(num)+".jpg",frame)
        print("success to save"+str(num)+".jpg")
        print("-------------")
        num+=1
    elif k == ord(' '):
        break
#释放内存
cv.destroyAllWindows()
#释放摄像头
cap.release()
